﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site/QuanTriHeThong/QuanTriHeThong_OffCanvas.Master" AutoEventWireup="true" CodeBehind="DMXaPhuong.aspx.cs" Inherits="HospitalManager.QuanTriHeThong.DanhMuc.DMXaPhuong" %>

<%@ Register Src="HeThongDanhMuc_LeftMenu.ascx" TagName="HeThongDanhMuc_LeftMenu" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(function () {
            $("#li_dmxaphuong").addClass("active");
            $("#li_hethongdanhmuc").addClass("active");
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="LeftContent" runat="server">
    <uc1:HeThongDanhMuc_LeftMenu ID="HeThongDanhMuc_LeftMenu1" runat="server" />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div class="row">
        <div class="col-xs-12 col-md-12">
            <div class="page-header" style="margin: 0 0 10px;">
                <h1 style="margin: 0; font-weight: bold; color: #3070A7; font-size: 30px;">
                    <small class="breadcrumb" style="font-size: 50%; background-color: #ffffff; padding: 0 15px;">
                        <li><a href="/he-thong/danh-muc">HỆ THỐNG DANH MỤC</a></li>
                        <li class="active">DANH MỤC XÃ PHƯỜNG</li>
                    </small>
                </h1>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="form-horizontal">
            <div class="col-xs-2 col-md-2">
                <div class="form-group">
                    <label class="col-sm-6 control-label">
                        Mã xã phường</label>
                    <div class="col-sm-6">
                        <asp:TextBox ID="txtMaXaPhuong" runat="server" CssClass="form-control"></asp:TextBox>
                    </div>
                </div>
            </div>
            <div class="col-xs-4 col-md-4">
                <div class="form-group">
                    <label class="col-sm-3 control-label">
                        Tên xã phường</label>
                    <div class="col-sm-9">
                        <asp:TextBox ID="txtTenXaPhuong" runat="server" CssClass="form-control"></asp:TextBox>
                    </div>
                </div>
            </div>
            <div class="col-xs-3 col-md-3">
                <div class="form-group">
                    <label class="col-sm-3 control-label">
                        Quận huyện</label>
                    <div class="col-sm-9">
                        <asp:DropDownList ID="ddlQuanHuyen" runat="server" data-live-search="true">
                        </asp:DropDownList>
                    </div>
                </div>
            </div>
            <div class="col-xs-3 col-md-3">
                <div class="form-group">
                    <div class="col-sm-12">
                        <asp:Button ID="btnLuu" runat="server" Text="Lưu" CssClass="btn btn-info" OnClick="btnLuu_Click"
                            OnClientClick="validation_form()" />
                        <asp:Button ID="btnTimKiem" runat="server" Text="Tìm kiếm" CssClass="btn btn-success"
                            OnClick="btnTimKiem_Click" OnClientClick="$('#form_Main').validate().cancelSubmit = true;" />
                        <asp:Button ID="btnXoa" runat="server" Text="Xóa" CssClass="btn btn-danger" OnClick="btnXoa_Click"
                            OnClientClick="return btnXoa_showconfirm(this.id);" />
                        <asp:Button ID="btnNhaplai" runat="server" Text="Nhập lại" CssClass="btn btn-warning"
                            OnClick="btnNhaplai_Click" OnClientClick="$('#form_Main').validate().cancelSubmit = true;" />
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="form-horizontal">
            <div class="col-xs-12 col-md-12">
                <div class="alert alert-warning" role="alert" style="margin-bottom: 0;">
                    <strong>Lưu ý !</strong>&nbsp;Hệ thống sẽ tự động bỏ dấu, khoảng trắng và viết hoa trường mã xã phường nếu trong đó có dấu và khoảng trắng.
                </div>
            </div>
        </div>
    </div>
    <div class="row" style="margin-top: 10px;">
        <div class="col-md-12">
            <div class="form-group">
                <asp:GridView ID="gvDanhMuc" runat="server" AutoGenerateColumns="False" Width="100%"
                    CssClass="table table-bordered table-condensed" OnRowCreated="gvDanhMuc_RowCreated"
                    DataKeyNames="MaXaPhuong">
                    <Columns>
                        <asp:TemplateField>
                            <HeaderTemplate>
                                <asp:CheckBox ID="checkall_id" runat="server" ToolTip="Chọn tất cả" onclick="javascript:checkallClick(this);" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="check_id" runat="server" />
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="5%" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="RowNumber" HeaderText="STT">
                            <ItemStyle HorizontalAlign="Center" Width="5%"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField DataField="MaXaPhuong" HeaderText="Mã xã phường"></asp:BoundField>
                        <asp:BoundField DataField="TenXaPhuong" HeaderText="Tên xã phường"></asp:BoundField>
                        <asp:BoundField DataField="TenQuanHuyen" HeaderText="Quận huyện"></asp:BoundField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="btnSua" runat="server" ToolTip="Sửa" CssClass="btn btn-info btn-sm"
                                    CommandArgument='<%# Eval("MaXaPhuong") %>' OnClick="btnSua_Click" OnClientClick="$('#form_Main').validate().cancelSubmit = true;">
                                        <i class="glyphicon glyphicon-edit"></i>
                                </asp:LinkButton>
                                <asp:LinkButton ID="btnDelete" runat="server" ToolTip="Xóa" CssClass="btn btn-danger btn-sm"
                                    CommandArgument='<%# Eval("MaXaPhuong") %>' OnClick="btnDelete_Click" OnClientClick="return showconfirm(this.id);">
                                        <i class="glyphicon glyphicon-trash"></i>
                                </asp:LinkButton>
                            </ItemTemplate>
                            <HeaderStyle Width="10%" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
        </div>
        <div class="col-md-6" style="text-align: right;">
            <asp:DataList RepeatDirection="Horizontal" runat="server" ID="dlPager" OnItemCommand="dlPager_ItemCommand"
                CssClass="tbPage">
                <ItemTemplate>
                    <asp:LinkButton Enabled='<%#Eval("Enabled") %>' runat="server" ID="lnkPageNo" Text='<%#Eval("Text") %>'
                        CommandArgument='<%#Eval("Value") %>' CommandName="PageNo"></asp:LinkButton>
                </ItemTemplate>
            </asp:DataList>
        </div>
    </div>
    <asp:HiddenField ID="hfStatus" runat="server" Value="false" />
    <asp:HiddenField ID="hfTimKiem" runat="server" Value="false" />
    <asp:HiddenField ID="hfPageIndex" runat="server" Value="1" />
    <script type="text/javascript">
        var TotalChkBx;
        var Counter;

        $(function () {
            TotalChkBx = parseInt("<%= gvDanhMuc.Rows.Count %>");
            Counter = 0;

            $("#<%=ddlQuanHuyen.ClientID %>").parent().find(".dropdown-toggle").bind("keydown", function (e) {
                if (e.which === 13) {
                    e.preventDefault();
                    $("#<%=btnLuu.ClientID %>").focus();
                }
            });
        });

        function validation_form() {
            $("#<%=txtMaXaPhuong.ClientID %>").rules("add", {
                required: true,
                messages: {
                    required: MsErrorEmpty
                }
            });
            $("#<%=txtTenXaPhuong.ClientID %>").rules("add", {
                required: true,
                messages: {
                    required: MsErrorEmpty
                }
            });
            $("#<%=ddlQuanHuyen.ClientID %>").rules("add", {
                required: true,
                messages: {
                    required: MsErrorEmpty
                }
            });
        }

        function checkallClick(checkBox) {
            var targetBaseControl = document.getElementById("<%= gvDanhMuc.ClientID %>");
            var targetChildControl = "check_id";
            var inputs = targetBaseControl.getElementsByTagName("input");
            for (var n = 0; n < inputs.length; ++n)
                if (inputs[n].type === "checkbox" && inputs[n].id.indexOf(targetChildControl, 0) >= 0)
                    inputs[n].checked = checkBox.checked;
            Counter = checkBox.checked ? TotalChkBx : 0;
        }

        function checkClick(checkBox, hCheckBox) {
            var headerCheckBox = document.getElementById(hCheckBox);
            if (checkBox.checked && Counter < TotalChkBx) Counter++;
            else if (Counter > 0) Counter--;
            if (Counter < TotalChkBx) headerCheckBox.checked = false;
            else if (Counter === TotalChkBx) headerCheckBox.checked = true;
        }

        //Hiển thị confirm  có muốn xóa hay ko?
        var confirmed = false;

        function btnXoa_showconfirm(controlId) {
            if (Counter === 0) {
                bootbox.alert("Bạn cần chọn bản ghi trước khi xóa!");
            } else {
                if (confirmed) { return true; }
                bootbox.confirm("Bạn có chắc chắn xóa?", function (result) {
                    if (result) {
                        if (controlId != null) {
                            var controlToClick = document.getElementById(controlId);
                            if (controlToClick != null) {
                                confirmed = true;
                                $("#form_Main").validate().cancelSubmit = true;
                                controlToClick.click();
                                confirmed = false;
                            }
                        }
                    }
                });
            }
            return false;
        }

        function showconfirm(controlId) {
            if (confirmed) return true;
            bootbox.confirm("Bạn có chắc chắn xóa?", function (result) {
                if (result) {
                    if (controlId != null) {
                        var controlToClick = document.getElementById(controlId);
                        if (controlToClick != null) {
                            confirmed = true;
                            $("#form_Main").validate().cancelSubmit = true;
                            controlToClick.click();
                            confirmed = false;
                        }
                    }
                }
            });
            return false;
        }
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="FormContent" runat="server">
</asp:Content>

